package src.Aula08.Ex2;

import java.util.ArrayList;

public class Prato {
    private String nome;
    private ArrayList<Alimento> alimentos;

    public Prato(String nome) {
        this.nome = nome;
        this.alimentos = new ArrayList<Alimento>();
    }

    @Override
    public String toString() {
        String s = String.format("Prato '%s', composto por %d ingredientes", nome, alimentos.size());
        return s;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((alimentos == null) ? 0 : alimentos.hashCode());
        result = prime * result + ((nome == null) ? 0 : nome.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Prato other = (Prato) obj;
        if (alimentos == null) {
            if (other.alimentos != null)
                return false;
        } else if (!alimentos.equals(other.alimentos))
            return false;
        if (nome == null) {
            if (other.nome != null)
                return false;
        } else if (!nome.equals(other.nome))
            return false;
        return true;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public ArrayList<Alimento> getAlimentos() {
        return alimentos;
    }

    public void setAlimentos(ArrayList<Alimento> alimentos) {
        this.alimentos = alimentos;
    }

    public double totalProteinas() {
        double totalProteinas = 0;
        for (Alimento alimento : alimentos)
            totalProteinas += alimento.getProteinas();
        return totalProteinas;
    }

    public double totalCalorias() {
        double totalCalorias = 0;
        for (Alimento alimento : alimentos)
            totalCalorias += alimento.getCalorias();
        return totalCalorias;
    }

    public double totalPeso() {
        double totalPeso = 0;
        for (Alimento alimento : alimentos)
            totalPeso += alimento.getPeso();
        return totalPeso;
    }

    public boolean addIngrediente(Alimento alimento) {
        this.alimentos.add(alimento);
        return true;
    }

}
